<template>

  <a-card :bordered='false'>

    <!-- 查询区域 -->
    <div class='table-page-search-wrapper'>
      <a-form layout='inline' @keyup.enter.native='searchQuery'>
        <a-row :gutter='24'>

          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <a-form-item label='大区'>
              <a-select default-value=''
                        placeholder='请选择大区'
                        v-model='queryParam.region'
                        :getPopupContainer='(target) => target.parentNode'
                        allowClear>
                <a-select-option value='东北区'>东北区</a-select-option>
                <a-select-option value='西北区'>西北区</a-select-option>
                <a-select-option value='东南区'>东南区</a-select-option>
                <a-select-option value='西南区'>西南区</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>

          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <a-form-item label='经销商编码'>
              <a-input placeholder='请输入经销商编码' v-model='queryParam.custCode'></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <a-form-item label='查询某省'>
              <a-input placeholder='请输入省名称' v-model='queryParam.province'
                       v-decorator="['province', {}]"></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <a-form-item label='查询某市'>
              <a-input placeholder='请输入市名称' v-model='queryParam.city'
                       v-decorator="['city', {}]"></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <a-form-item label='查询某区'>
              <a-input placeholder='请输入区名称' v-model='queryParam.area'
                       v-decorator="['area', {}]"></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <a-form-item label='门店编码'>
              <a-input placeholder='请输入门店编码模糊查询' v-model='queryParam.terminalCode'></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <a-form-item
              label='渠道类型'>
              <cn-dict-select-tag placeholder='请选择渠道类型' dict-code='term_channel' v-model='queryParam.channel' />
            </a-form-item>
          </a-col>

          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <a-form-item label='是否总仓'>
              <a-select default-value=''
                        placeholder='请选择'
                        v-model='queryParam.storeName'
                        :getPopupContainer='(target) => target.parentNode'
                        allowClear>
                <a-select-option value='是'>是</a-select-option>
                <a-select-option value='否'>否</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>

          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <a-form-item label='总仓门店编码'>
              <a-input placeholder='请输入总仓门店编码模糊查询' v-model='queryParam.paretTermCode'></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <a-form-item label='总仓门店名称'>
              <a-input placeholder='请输入总仓门店名称模糊查询' v-model='queryParam.prentTermName'></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <a-form-item label='直供/间供'>
              <a-select default-value=''
                        placeholder='请选择'
                        v-model='queryParam.supply'
                        :getPopupContainer='(target) => target.parentNode'
                        allowClear>
                <a-select-option value='直供'>直供</a-select-option>
                <a-select-option value='间供'>间供</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>

          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <a-form-item label='门店联系人'>
              <a-input placeholder='请输入门店联系人模糊查询' v-model='queryParam.linkman'></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <a-form-item label='门店联系电话'>
              <a-input placeholder='请输入门店联系电话模糊查询' v-model='queryParam.telephone'></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <a-form-item label='品牌'>
              <a-input placeholder='请输入品牌' v-model='queryParam.brandName'></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <a-form-item label='品类'>
              <a-input placeholder='请输入品类' v-model='queryParam.productType'></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <a-form-item label='商品编码'>
              <a-input placeholder='请输入商品编码' v-model='queryParam.productCode'></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <a-form-item label='批次'>
              <a-input placeholder='请输入批次' v-model='queryParam.flot'></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <a-form-item
              label='类型'>
              <cn-dict-select-tag placeholder='请选择类型' dict-code='stock_type' v-model='queryParam.stockType' />
            </a-form-item>
          </a-col>

          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <a-form-item label='日期'>
              <a-range-picker style='width:100%'
                              format='YYYY-MM-DD'
                              valueFormat='YYYY-MM-DD'
                              v-model='queryParam.ymS'
                              @openChange='onOpenChange'
                              @calendarChange='onCalendarChange'
                              @change='onChangeTimer'
              >
              </a-range-picker>
            </a-form-item>
          </a-col>

          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <span style='float: left;overflow: hidden;' class='table-page-search-submitButtons'>
              <a-button type='primary' @click='searchQuery' icon='search'>查询</a-button>
              <a-button type='primary' @click='searchReset' icon='reload' style='margin-left: 8px'>重置</a-button>
              <a @click='handleToggleSearch' style='margin-left: 8px'>
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class='table-operator'>
      <!--      <a-button type="primary" icon="update" @click="doSellOutData">数据更新</a-button>-->
      <a-button type='primary' icon='download' @click="downExportXls2('sell_out_detail_report',queryParam.ymS)">导出
      </a-button>
    </div>
    <!-- 操作按钮区域 -->


    <!-- table区域-begin --> <!--<div class="table-operator">-->
    <!--<a-dropdown v-if="selectedRowKeys.length > 0">-->
    <!--<a-menu slot="overlay">-->
    <!--<a-menu-item key="1" @click="updateApprovalBatch">-->
    <!--<a-icon type="text"/>-->
    <!--审批-->
    <!--</a-menu-item>-->
    <!--</a-menu>-->
    <!--<a-button style="margin-left: 8px"> 批量操作-->
    <!--<a-icon type="down"/>-->
    <!--</a-button>-->
    <!--</a-dropdown>-->
    <!--</div>-->
    <div>
      <div class='ant-alert ant-alert-info' style='margin-bottom: 16px;'>
        <i class='anticon anticon-info-circle ant-alert-icon'></i> 已选择 <a style='font-weight: 600'>{{
          selectedRowKeys.length }}</a>项
        <a style='margin-left: 24px' @click='onClearSelected'>清空</a>
      </div>

      <a-table
        ref='table'
        size='middle'
        bordered
        rowKey='id'
        :columns='columns'
        :dataSource='dataSource'
        :pagination='ipagination'
        :loading='loading'
        class='j-table-force-nowrap'
        :rowSelection='{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}'
        @change='handleTableChange'>


      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <!--<sfaPicFactory-modal ref="modalForm" @ok="modalFormOk"></sfaPicFactory-modal>-->
  </a-card>
</template>
<script>
import '@/assets/less/TableExpand.less'
import { PageListMixin } from '@/mixins/PageListMixin'
import { postAction } from '@/api/manage'
import ARow from 'ant-design-vue/es/grid/Row'
import moment from 'moment'

export default {
  name: 'SfaPicUploadList',
  mixins: [PageListMixin],
  components: {
    ARow
  },
  data() {
    return {
      description: 'sellOut页面',
      disabledCurrent: null,
      fromTime: null,
      toTime: null,
      type: null,
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '大区',
          align: 'center',
          dataIndex: 'region'
        },
        {
          title: '经销商编码',
          align: 'center',
          dataIndex: 'custCode'
        },
        {
          title: '经销商名称',
          align: 'center',
          dataIndex: 'custName'
        },
        {
          title: '省',
          align: 'center',
          dataIndex: 'province'
        },
        {
          title: '市',
          align: 'center',
          dataIndex: 'city'
        }, {
          title: '区',
          align: 'center',
          dataIndex: 'area'
        },
        {
          title: '门店编码',
          align: 'center',
          dataIndex: 'terminalCode'
        },
        {
          title: '门店名称',
          align: 'center',
          dataIndex: 'terminalName'
        },
        {
          title: '渠道类型',
          align: 'center',
          dataIndex: 'channel'
        },
        {
          title: '是否总仓',
          align: 'center',
          dataIndex: 'storeName'
        },
        {
          title: '总仓门店编码',
          align: 'center',
          dataIndex: 'paretTermCode'
        },
        {
          title: '总仓门店名称',
          align: 'center',
          dataIndex: 'prentTermName'
        },
        {
          title: '分销门店数',
          align: 'center',
          dataIndex: 'num'
        },
        {
          title: '直供/间供',
          align: 'center',
          dataIndex: 'supply'
        },
        {
          title: '门店联系人',
          align: 'center',
          dataIndex: 'linkman'
        },
        {
          title: '门店联系电话',
          align: 'center',
          dataIndex: 'telephone'
        },
        {
          title: '品牌',
          align: 'center',
          dataIndex: 'brandName'
        },
        {
          title: '品类',
          align: 'center',
          dataIndex: 'productType'
        },
        {
          title: '商品编码',
          align: 'center',
          dataIndex: 'productCode'
        },
        {
          title: '商品名称',
          align: 'center',
          dataIndex: 'productName'
        },
        {
          title: '批次',
          align: 'center',
          dataIndex: 'flot'
        },
        {
          title: '生产日期',
          align: 'center',
          dataIndex: 'productDate'
        },
        {
          title: '数量',
          align: 'center',
          dataIndex: 'orderNum'
        },
        {
          title: '类型',
          align: 'center',
          dataIndex: 'stockType'
        },
        {
          title: '日期',
          align: 'center',
          dataIndex: 'sellDate'
        }
      ],
      url: {
        list: window._CONFIG['domianSfaURL'] + '/sy/sellOutDetailController/findPageList',
        doSellOutData: window._CONFIG['domianSfaURL'] + '/sy/sellOutDetailController/doSellOutDetailData'
      }
    }
  },
  methods: {
    doSellOutData() {
      var that = this
      if (!this.url || !this.url.doSellOutData) {
        // this.$message.error("请设置url.list属性!")
        return
      }
      // var params = this.getQueryParams();//查询条件
      this.loading = true
      postAction(this.url.doSellOutData).then((res) => {
        if (res.success) {
          that.$message.success(res.message)
          that.loadData()
        } else {
          that.$message.warning(res.message)
        }
        that.loading = false
      })
    },
    downExportXls2(key, dates) {
      // if (dates == null || dates.length < 2){
      //    this.$message.warn('请选择日期!')
      //    return
      // }
      const downurl = window._CONFIG['domianURL'] + '/cnDownloadController/saveOrUpdate'
      if (!key || typeof key != 'string') {
        this.$message.warning('未配置接口标记！')
        return
      }
      let param = { ...this.queryParam }
      let expParams = JSON.stringify(param)
      expParams = escape(expParams)
      postAction(downurl, { impKey: key, expParams: expParams }).then((res) => {
        if (res.success) {
          this.$message.info(res.message + ',等待下载完成')
        } else {
          this.$message.warn(res.message)
        }
      })
    },
    /**
     * 清空禁用时间段的设置
     */
    onOpenChange(status) {
      // 清空禁用时间段的设置
      this.disabledCurrent = null
    },
    /**
     * 获取手动选择的时间段起始值
     */
    onCalendarChange(dates) {
      // 获取手动选择的时间段起始值
      this.disabledCurrent = dates[0]
    },
    /**
     * 时间控制切换赋值
     */
    onChangeTimer(moment, data) {
      this.fromTime = data[0]
      this.toTime = data[1]
    },
    /**
     * 1、时间限制范围 开始时间~结束时间不能超过31天
     */
    disabledDate(current) {
      if (!this.disabledCurrent) return false

      return (current && current < moment(this.disabledCurrent).subtract(1, 'M').startOf('day')) || current > moment(this.disabledCurrent).add(1, 'M').endOf('day')
    }
  }
}
</script>

<style scoped>
@import '~@assets/less/common.less';

</style>